//
//  SEMedicalRecordInfo.m
//  kuaiyi
//
//  Created by Zhu Jinxin on 16/7/6.
//  Copyright © 2016年 Alphts. All rights reserved.
//
//本类是九宫格按钮点击后跳入的下一个界面
#import "SEMedicalRecordInfo.h"
#import "CustomTF2.h"
#import "SEProvineController.h"
#import "SETreatmentMethodTableViewController.h"
#import "SESyndromeController.h"
#import "SESyndromeDTO.h"
#import "SEDiseaseView.h"
#import "SESubDieaseViewController.h"
#import "SEFocusController.h"

#define kScreenSize [UIScreen mainScreen].bounds.size

#define kItemSize CGSizeMake(kScreenSize.width*0.9, kScreenSize.height*0.044)

#define kMargin kScreenSize.width*0.026

#define kMarginLong kScreenSize.width*0.05

#define kLongBTMsize CGSizeMake(kScreenSize.width*0.9, kScreenSize.height*0.06)

@interface SEMedicalRecordInfo ()

@property(nonatomic,strong) UILabel* usrInfoLabel;

@property(nonatomic,strong) UILabel* diseaseTypeLabel;

@property(nonatomic,strong) SEDiseaseView * hiddenView;

@property(nonatomic,strong) CustomTF2 * TFSec1;

@property(nonatomic,strong) CustomTF2 * TFSec2;

@end

@implementation SEMedicalRecordInfo

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
    
}

- (void)setupUI{
    
    //第一行的Lable
    
    UILabel *usrInfoLabel = [[UILabel alloc]init];
    usrInfoLabel.text = @"用户信息:  王二狗 1000099";
    usrInfoLabel.textAlignment = NSTextAlignmentLeft;
    usrInfoLabel.font = [UIFont boldSystemFontOfSize:20];
    _usrInfoLabel = usrInfoLabel;
    [self.view addSubview:_usrInfoLabel];
    
    [_usrInfoLabel makeConstraints:^(MASConstraintMaker *make) {
        
        //距离顶部
        make.top.equalTo(self.view).offset(kScreenSize.width*0.026 + 64);
        
        //Size
        make.size.equalTo(CGSizeMake(kScreenSize.width*0.9, kScreenSize.height*0.044));
        
        //中心点
        make.centerX.equalTo(self.view.centerX);
        
        
    }];

    
    //----------------------第二行的Label-------------------------
    
    UILabel *diseaseTypeLabel = [[UILabel alloc]init];
    
    diseaseTypeLabel.font = [UIFont boldSystemFontOfSize:20];
    diseaseTypeLabel.textAlignment = NSTextAlignmentLeft;
    _diseaseTypeLabel = diseaseTypeLabel;
    [self.view addSubview:diseaseTypeLabel];
    
    [_diseaseTypeLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.usrInfoLabel.bottom).offset(kMargin);
        make.size.equalTo(kItemSize);
        make.centerX.equalTo(usrInfoLabel.centerX);
        
        
    }];
    
    //------------------------第三行的view-----------------------
    SEDiseaseView *vw_disease = [[SEDiseaseView alloc] initWithPlaceholder:@" 请选择疾病细分"];
    [self.view addSubview:vw_disease];
    
    [vw_disease makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.diseaseTypeLabel.bottom).offset(kMargin);
        make.size.equalTo(kLongBTMsize);
        make.centerX.equalTo(usrInfoLabel.centerX);
        
    }];
    
    __block SEDiseaseView *weak_vw_disease = vw_disease;
    vw_disease.accessoryBlock = ^{
      
        SESubDieaseViewController *vc = [[SESubDieaseViewController alloc] init];
        
        [vc setDetailDieaseBlock:^(NSString *message) {
            
            weak_vw_disease.message = message;
            
        }];
        
        [self.navigationController pushViewController:vc animated:YES];
    };
    
    
    //MARK: 4 第四行的view-----------------------
    
    SEDiseaseView *vw_syndrome = [[SEDiseaseView alloc] initWithPlaceholder:@" 请选择并发症(可多选)"];
    [self.view addSubview:vw_syndrome];

    [vw_syndrome makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(vw_disease.bottom).offset(kMarginLong);
        make.size.equalTo(kLongBTMsize);
        make.centerX.equalTo(usrInfoLabel.centerX);
        
    }];
    
    __block SEDiseaseView *weakView = vw_syndrome;
    //实现并发症多选 block回调
    vw_syndrome.accessoryBlock = ^{
      
        SESyndromeController *synVc = [[SESyndromeController alloc] init];
        
        synVc.title = @"并发症";
        
        synVc.syndromeBlock = ^(NSArray *modelArray){
            
            //拼接字符串,给btn赋值
            NSMutableString *mStr = [NSMutableString string];
            
            [modelArray enumerateObjectsUsingBlock:^(SESyndromeDTO *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                if (idx == modelArray.count - 1) {
                    [mStr appendString:obj.title];
                }else{
                    [mStr appendString:[NSString stringWithFormat:@"%@、",obj.title]];
                }
                
            }];
            weakView.message = mStr.copy;
            
        };
        
        [self.navigationController pushViewController:synVc animated:YES];
    };
    
    
    //MARK: 5 第五行的TextFiled
    
    CustomTF2 *TFSec1 = [[CustomTF2 alloc] init];
    TFSec1.titleLabel.font = FONT(16);
    self.TFSec1 = TFSec1;
    
    
    
    _TFSec1.backgroundColor = [UIColor whiteColor];
    [_TFSec1 setTitle:@" 是否确诊" forState:UIControlStateNormal];
    [_TFSec1.button2 setTitle:@" 症状疑似" forState:UIControlStateNormal];
    
    
    [_TFSec1 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    _TFSec1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _TFSec1.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    
    [_TFSec1.button1 setTitle:@" 已确诊" forState:UIControlStateNormal];
    
    [self.view addSubview:_TFSec1];
    
    [_TFSec1 makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(vw_syndrome.bottom).offset(kMarginLong);
        make.size.equalTo(kLongBTMsize);
        make.centerX.equalTo(usrInfoLabel.centerX);
        
    }];
    
    //MARK: 6 第六行的TextFiled------------------------
    
    CustomTF2 *TFSec2 = [[CustomTF2 alloc] init];
    TFSec2.titleLabel.font = FONT(16);
    self.TFSec2 = TFSec2;
    
    _TFSec2.backgroundColor = [UIColor whiteColor];
    [_TFSec2 setTitle:@" 是否治疗过" forState:UIControlStateNormal];
    [_TFSec2.button2 setTitle:@" 未接受过" forState:UIControlStateNormal];
    [_TFSec2 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    _TFSec2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _TFSec2.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    
    [_TFSec2.button1 setTitle:@" 接受过" forState:UIControlStateNormal];
    
    [self.view addSubview:_TFSec2];
    
    [_TFSec2 makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_TFSec1.bottom).offset(kMarginLong);
        make.size.equalTo(kLongBTMsize);
        make.centerX.equalTo(usrInfoLabel.centerX);
        
    }];
    
    __weak SEMedicalRecordInfo *weakSelf = self;
    
    _TFSec2.showBlcok = ^{
        
        weakSelf.hiddenView.hidden = NO;
    };
    
    _TFSec2.hiddenBlcok = ^{
        
        weakSelf.hiddenView.hidden = YES;
    };
    
    //-MARK: 7 HiddenLabel(第七行)---------------------------

    
    SEDiseaseView *vw_cure = [[SEDiseaseView alloc] initWithPlaceholder:@"接受了何种治疗"];
    
    self.hiddenView = vw_cure;
    
    vw_cure.hidden = YES;
    
    [self.view addSubview:vw_cure];
    
    [vw_cure makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_TFSec2.bottom).offset(kMarginLong);
        make.size.equalTo(kLongBTMsize);
        make.centerX.equalTo(usrInfoLabel.centerX);
        
    }];
    __block SEDiseaseView *weak_vw_cure = vw_cure;
    vw_cure.accessoryBlock = ^{
        
        SETreatmentMethodTableViewController *con = [SETreatmentMethodTableViewController new];
        
        con.myBlock = ^(NSString *str){
            
            weak_vw_cure.message = str;

        };
        
        con.title = @"治疗方式";
        
        [self.navigationController pushViewController:con animated:YES];
    };
    

    
    //-------------------为您找到x位医生Label----------------------------
    
    //找到几位医生接口
    int docNum  = arc4random_uniform(30);
    
    UILabel* findDocLabel = [UILabel new];
    findDocLabel.text = [NSString stringWithFormat:@"为您匹配到 %d 位医生",docNum];
    
    findDocLabel.font = [UIFont boldSystemFontOfSize:20];
    findDocLabel.textColor = [UIColor blackColor];
    
    [findDocLabel sizeToFit];
    
    [self.view addSubview: findDocLabel];
    
    [findDocLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.hiddenView.bottom).offset(kScreenSize.width*0.13);
        make.centerX.equalTo(self.view.centerX);
        
        
    }];
    
    //--------------------圆形图片---------------------------
    
    UIImageView* rotundityImage = [[UIImageView alloc]init];
    
    rotundityImage.image = [UIImage imageNamed:@"illness_img_person.png"];
    
    [self.view addSubview:rotundityImage];
    
    [rotundityImage makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(findDocLabel.bottom).offset(kMarginLong);
        make.centerX.equalTo(self.view.centerX);
        make.size.equalTo(CGSizeMake(kScreenSize.width*0.16, kScreenSize.width*0.16));
        
    }];
    
    //--------------------底部Button---------------------------

    UIButton *bottomButton = [UIButton new];
    [bottomButton setBackgroundImage:[UIImage imageNamed:@"nav"] forState:UIControlStateNormal];
    [bottomButton setTitle:@"就医申请" forState:UIControlStateNormal];
    [bottomButton addTarget:self action:@selector(bottomButtonMethod:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:bottomButton];
    
    [bottomButton makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.offset(-kMargin);
        make.height.equalTo(kScreenSize.width*0.08);
        make.width.equalTo([UIScreen mainScreen].bounds.size.width *0.9);
        make.centerX.equalTo(self.view.centerX);
        
    }];
    
}


//设置疾病类型Label文字
- (void)setMytitle:(NSString *)mytitle{
    _mytitle = mytitle;

    _diseaseTypeLabel.text = [NSString stringWithFormat:@"疾病类型:  %@",self.title];
    
}

#pragma mark - 点击按底部按钮执行的方法
-(void)bottomButtonMethod:(UIButton*)sender{

    [self.navigationController pushViewController:[[SEFocusController alloc] init] animated:YES];
    
}





@end
